#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    map<int, int> mp;
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i]; 
        sum += a[i];
        mp[sum] = i;
    }
    if(sum < k) {
        cout << -1 << endl;
        return;
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        ans = max(ans, mp[k] - i + 1);
        if(a[i] == 1) k++;
    }
    cout << n - ans << endl;
}

signed main() {
    int t = 1;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}